<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.db.conn"%>
<%@ page import="java.sql.*"%>
<%@ page import="com.db.Pagination" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
<jsp:include flush="true" page="${basePath}/admin/head.jsp"></jsp:include>
<link rel="stylesheet" href="<%=path %>/kindeditor/themes/default/default.css" />
<link rel="stylesheet" href="<%=path %>/kindeditor/plugins/code/prettify.css" />
<script charset="utf-8" src="<%=path %>/kindeditor/kindeditor.js"></script>
<script charset="utf-8" src="<%=path %>/kindeditor/lang/zh_CN.js"></script>
<script charset="utf-8" src="<%=path %>/kindeditor/plugins/code/prettify.js"></script>
<script>
    KindEditor.ready(function(K) {
        var editor1 = K.create('textarea[name="Textarea1"]', {
            cssPath : '<%=path %>/kindeditor/plugins/code/prettify.css',
            uploadJson : '<%=path %>/kindeditor/jsp/upload_json.jsp',
            fileManagerJson : '<%=path %>/kindeditor/jsp/file_manager_json.jsp',
            allowFileManager : true,
            afterCreate : function() {
                var self = this;
                K.ctrl(document, 13, function() {
                    self.sync();
                    document.forms['example'].submit();
                });
                K.ctrl(self.edit.doc, 13, function() {
                    self.sync();
                    document.forms['example'].submit();
                });
            }
        });
        prettyPrint();
    });
</script>

<script src="<%=path %>/admin/js/jquery.js" type="text/javascript"></script>
<script src="<%=path %>/admin/js/formValidator.js" type="text/javascript"></script>  
<script src="<%=path %>/admin/js/formValidatorRegex.js" type="text/javascript"></script>
<link href="<%=path %>/admin/css/validator.css" rel="stylesheet" type="text/css" />

<style>
.page-container {
    padding: 20px;
}

.form-section {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin-bottom: 30px;
    padding: 20px;
}

.form-section h6 {
    margin-bottom: 20px;
    color: #333;
    font-weight: 600;
}

.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: #333;
}

.required-mark {
    color: #dc3545;
    margin-right: 4px;
}

.form-control {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    transition: border-color 0.15s ease-in-out;
}

.form-control:focus {
    border-color: #80bdff;
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(0,123,255,.25);
}

.error-tip {
    color: #dc3545;
    font-size: 12px;
    margin-top: 4px;
}

.editor-container {
    margin-top: 10px;
}

.button-group {
    margin-top: 30px;
    text-align: center;
}

.btn {
    padding: 8px 20px;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 0 5px;
}

.btn-primary {
    background-color: #007bff;
    border: 1px solid #007bff;
    color: white;
}

.btn-primary:hover {
    background-color: #0069d9;
    border-color: #0062cc;
}

.btn-secondary {
    background-color: #6c757d;
    border: 1px solid #6c757d;
    color: white;
}

.btn-secondary:hover {
    background-color: #5a6268;
    border-color: #545b62;
}

.chapter-list {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    padding: 20px;
}

.chapter-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}

.chapter-table th {
    background-color: #f8f9fa;
    padding: 12px;
    text-align: left;
    font-weight: 600;
    color: #333;
    border-bottom: 2px solid #dee2e6;
}

.chapter-table td {
    padding: 12px;
    border-bottom: 1px solid #dee2e6;
    color: #666;
}

.chapter-table tr:hover {
    background-color: #f8f9fa;
}

.action-links {
    display: flex;
    gap: 8px;
}

.action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    border: 1px solid transparent;
}

.action-btn.detail {
    background-color: #e6f7ff;
    color: #1890ff;
    border-color: #91d5ff;
}

.action-btn.detail:hover {
    background-color: #bae7ff;
    border-color: #69c0ff;
    color: #40a9ff;
}

.action-btn.delete {
    background-color: #fff1f0;
    color: #ff4d4f;
    border-color: #ffa39e;
}

.action-btn.delete:hover {
    background-color: #ffa39e;
    border-color: #ff7875;
    color: #fff;
}

.pagination {
    margin-top: 30px;
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 5px;
}

.pagination a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 12px;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    color: #666;
    text-decoration: none;
    font-size: 14px;
    transition: all 0.2s ease;
    background: #fff;
}

.pagination a:hover {
    background-color: #f5f5f5;
    border-color: #d0d0d0;
    color: #333;
}

.pagination .active {
    background-color: #1890ff;
    border-color: #1890ff;
    color: white;
}

.pagination .active:hover {
    background-color: #40a9ff;
    border-color: #40a9ff;
    color: white;
}

.pagination .disabled {
    color: #d9d9d9;
    background-color: #f5f5f5;
    border-color: #d9d9d9;
    cursor: not-allowed;
    pointer-events: none;
}

.pagination .ellipsis {
    color: #999;
    padding: 0 8px;
}

.pagination .prev,
.pagination .next {
    background-color: #f5f5f5;
}

.pagination .prev:hover,
.pagination .next:hover {
    background-color: #e8e8e8;
}
</style>

 </head>

 <body class="ms-body ms-aside-left-open ms-primary-theme ms-has-quickbar">
    <div class="ms-content-wrapper">
        <div class="row">
            <div class="col-md-12">
                <div class="page-container">
                    <!-- 添加章节表单部分 -->
                    <div class="form-section">
                        <h6>添加章节信息</h6>
                        <form action="<%=path %>/bmore_Add?id=<%=request.getParameter("id")%>" method="post">
                            <div class="form-group">
                                <label class="form-label">
                                    <span class="required-mark">*</span>章节名称
                                </label>
                                <div class="form-content">
                                    <input name="txt_mtitle" type="text" id="txt_mtitle" class="form-control" required/>
                                    <div id="txt_mtitleTip" class="error-tip"></div>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="form-label">
                                    <span class="required-mark">*</span>章节内容
                                </label>
                                <div class="form-content">
                                    <div class="editor-container">
                                        <textarea id="Textarea1" name="Textarea1" cols="100" rows="8" style="width:100%;height:400px;visibility:hidden;"></textarea>
                                    </div>
                                </div>
                            </div>

                            <div class="button-group">
                                <button type="submit" name="btnAdd" class="btn btn-primary" onclick="return jQuery.formValidator.PageIsValid('1');">添加章节</button>
                                <button type="button" class="btn btn-secondary" onclick="location.href='<%=path %>/admin/books/books_Manage.jsp'">返回</button>
                            </div>
                        </form>
                    </div>

                    <!-- 章节列表部分 -->
                    <div class="chapter-list">
                        <h6>章节列表</h6>
                        <%
                            int pageSize=15;
                            int pageNow=1;
                            int rowCount=0;
                            int pageCount=0;
                            String s_pageNow=request.getParameter("pageNum");
                            if(s_pageNow!=null){
                                pageNow=Integer.parseInt(s_pageNow);
                            }

                            String where="  bid="+request.getParameter("id");
                            conn cn=new conn();

                            ResultSet rs=cn.query("select count(*) from bmore a where "+where);
                            if(rs.next()){
                                rowCount=rs.getInt(1);
                            }

                            if(rowCount%pageSize==0){
                                pageCount=rowCount/pageSize;
                            }else{
                                pageCount=rowCount/pageSize+1;
                            }

                            rs=cn.query("select  * from bmore a where "+where+" order by mid desc limit "+pageSize*(pageNow-1)+", "+pageSize);
                        %>

                        <table class="chapter-table">
                            <thead>
                                <tr>
                                    <th>章节名称</th>
                                    <th>发布时间</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <% while(rs.next()){ %>
                                <tr>
                                    <td><%=rs.getString("mtitle") %></td>
                                    <td><%=rs.getString("mtime") %></td>
                                    <td>
                                        <div class="action-links">
                                            <a href="<%=path %>/admin/bmore/bmore_Detail.jsp?id=<%=rs.getString("mid") %>" class="action-btn detail">详细</a>
                                            <a href="<%=path %>/bmore_Delete?id=<%=rs.getString("mid") %>" class="action-btn delete" onclick="return confirm('确定要删除这个章节吗？')">删除</a>
                                        </div>
                                    </td>
                                </tr>
                                <%} %>
                            </tbody>
                        </table>

                        <div class="pagination">
                            <%= Pagination.getPagination(pageNow,pageCount,rowCount,request.getRequestURI()) %>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

<script language="javascript" type="text/javascript">
    $(document).ready(function() {
        $.formValidator.initConfig({ onError: function(msg) { alert(msg) } });

        $("#txt_mtitle").formValidator({ 
            onshow: "请输入章节名称", 
            onfocus: "章节名称不能为空", 
            oncorrect: "合法" 
        }).InputValidator({ 
            min: 1, 
            onerror: "章节名称不能为空,请确认" 
        });
    });
</script>

</body>
</html>









